﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernateUnitOfWork;
using XWord.Fundamental.Domain;
using NHibernate.Criterion;
using System.IO;

namespace ConsoleApplication1
{
    public class QuestionTest
    {
        public static void Test1()
        {
            IList<RCArticle> list = UnitOfWork.CurrentSession.CreateCriteria<RCArticle>()
                .List<RCArticle>().Where(e => e.CreateTime.Year == 2009 && e.CreateTime.Month == 12).ToList();
            RCArticle art = list[0];

            string[] questions=new string[]{
            "Why does Michelle Obama hold a strong fascination for the author?",
            "What is the common stereotype of African-American women according to the author?",
            "What do many African-Americans write about in their blogs?",
            "What does the author say about Michelle Obama as a First Lady?",
            "What do many African-American women hope Michelle Obama will do?",
            };
            for (int i = 0; i < questions.Length; i++)
            {
                Question item = new Question();
                item.Sentence = questions[i];
                item.Priority = i;
                art.Questions.Add(item);
            }
            UnitOfWork.CurrentSession.Flush();
        }

        public static void Test2()
        {
            IList<RCArticle> list = UnitOfWork.CurrentSession.CreateCriteria<RCArticle>()
                .List<RCArticle>().Where(e => e.CreateTime.Year == 2009 && e.CreateTime.Month == 12).ToList();
            RCArticle art = list[0];
            var listQuestion = art.Questions.ToList();
            string answers1 = @"A) She serves as a role model for African-American women.
B) She possesses many admirable qualities becoming a First Lady.
C) She will present to the world a new image of African-American women.
D) She will pay closer attention to the interests of African-American women.";
            string[] answerList1 = answers1.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList1[i].IndexOf(") ");
                answerList1[i] = answerList1[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList1[i];
                choice.Priority = i;
                listQuestion[0].Choices.Add(choice);
            }
           
            string answers2 = @"A) They are victims of family violence.
B) They are of an inferior social group.
C) They use quite a lot of body language.
D) They live on charity and social welfare.";
            string[] answerList2 = answers2.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList2[i].IndexOf(") ");
                answerList2[i] = answerList2[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList2[i];
                choice.Priority = i;
                listQuestion[1].Choices.Add(choice);
            }

            string answers3 = @"A) Whether Michelle can live up to the high expectations of her fans.
B) How Michelle should behave as a public figure.
C) How proud they are to have a black woman in the White House.
D) What Michelle should do as wife and mother in the White House.
";
            string[] answerList3 = answers3.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList3[i].IndexOf(") ");
                answerList3[i] = answerList3[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList3[i];
                choice.Priority = i;
                listQuestion[2].Choices.Add(choice);
            }

            string answers4 = @"A) However many fans she has, she should remain modest.
B) She shouldn’t disappoint the Afircan-American community.
C) However hard she tries, she can’t expect to please everybody.
D) She will give priority to African-American women’s concerns.
";
            string[] answerList4 = answers4.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList4[i].IndexOf(") ");
                answerList4[i] = answerList4[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList4[i];
                choice.Priority = i;
                listQuestion[3].Choices.Add(choice);
            }

            string answers5 = @"A) Help change the prevailing view about black women.
B) Help her husband in the task of changing America.
C) Outshine previous First Ladies.
D) Fully display her fine qualities.
";
            string[] answerList5 = answers5.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList5[i].IndexOf(") ");
                answerList5[i] = answerList5[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList5[i];
                choice.Priority = i;
                listQuestion[4].Choices.Add(choice);
            }
            
            UnitOfWork.CurrentSession.Flush();
        }

        public static void Test3()
        {
            IList<RCArticle> list = UnitOfWork.CurrentSession.CreateCriteria<RCArticle>()
                .List<RCArticle>().Where(e => e.CreateTime.Year == 2009 && e.CreateTime.Month == 12).ToList();
            RCArticle art = list[1];

            //string[] questions = new string[]{
            //"What is the current trend in higher education discussed in the passage?",
            //"What is the chief consideration of American universities when hiring top-level administrators?",
            //"What do we learn about European universities from the passage?",
            //"Cambridge University appointed Alison Richard as its vice-chancellor chiefly because ________.",
            //"In what way do top-level administrators from abroad contribute to university development?",
            //};
            //for (int i = 0; i < questions.Length; i++)
            //{
            //    Question item = new Question();
            //    item.Sentence = questions[i];
            //    item.Priority = i;
            //    art.Questions.Add(item);
            //}

            foreach (var item in art.Questions)
            {
                item.Choices.Clear();
            }
            UnitOfWork.CurrentSession.Flush();
        }

        public static void Test4()
        {
            IList<RCArticle> list = UnitOfWork.CurrentSession.CreateCriteria<RCArticle>()
                .List<RCArticle>().Where(e => e.CreateTime.Year == 2009 && e.CreateTime.Month == 12).ToList();
            RCArticle art = list[1];
            var listQuestion = art.Questions.ToList();
            
            string answers1 = @"A) Institutions worldwide are hiring administrators from the US.
B) A lot of political activists are being recruited as administrators.
C) American universities are enrolling more international students.
D) University presidents are paying more attention to fund-raising.";
            //TextReader a = new StringReader(answers1);
            
            string[] answerList1 = answers1.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList1[i].IndexOf(") ");
                answerList1[i] = answerList1[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList1[i];
                choice.Priority = i;
                listQuestion[0].Choices.Add(choice);
            }

            string answers2 = @"A) Their political correctness.
B) Their ability to raise funds.
C) Their fame in academic circles.
D) Their administrative experience.";
            string[] answerList2 = answers2.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList2[i].IndexOf(") ");
                answerList2[i] = answerList2[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList2[i];
                choice.Priority = i;
                listQuestion[1].Choices.Add(choice);
            }

            string answers3 = @"A) she was known to be good at raising money.
B) she could help strengthen its ties with Yale.
C) she knew how to attract students overseas.
D) she had boosted Yale’s academic status.";
            string[] answerList3 = answers3.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList3[i].IndexOf(") ");
                answerList3[i] = answerList3[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList3[i];
                choice.Priority = i;
                listQuestion[2].Choices.Add(choice);
            }

            string answers4 = @"A) They can enchance the university’s image.
B) They will bring with them more international faculty.
C) They will view a lot of things from a new perspective.
D) They can set up new academic disciplines.";
            string[] answerList4 = answers4.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList4[i].IndexOf(") ");
                answerList4[i] = answerList4[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList4[i];
                choice.Priority = i;
                listQuestion[3].Choices.Add(choice);
            }

            string answers5 = @"A) Help change the prevailing view about black women.
B) Help her husband in the task of changing America.
C) Outshine previous First Ladies.
D) Fully display her fine qualities.
";
            string[] answerList5 = answers5.Trim().Split(new char[] { '.' });
            for (int i = 0; i < 4; i++)
            {
                var index = answerList5[i].IndexOf(") ");
                answerList5[i] = answerList5[i].Substring(index + 1).Trim() + ".";
                Choice choice = new Choice();
                choice.Sentence = answerList5[i];
                choice.Priority = i;
                listQuestion[4].Choices.Add(choice);
            }

            UnitOfWork.CurrentSession.Flush();
        }
    }
}
